//
//  ByMoneyApi.m
//  caipiao_ios
//
//  Created by mc on 2018/8/6.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByMoneyApi.h"

@implementation ByMoneyApi


//充值接口
+ (void)recharge:(ByNetModel *)model
         success:(void(^)(ByNetBaseResult *result))success
         failure:(void(^)(ByNetBaseResult *result))failure{
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.money) {
        [params setObject:[NSString stringWithFormat:@"%ld", model.money.integerValue] forKey:@"money"];
    }
    NSLog(@"money = %@", model.money);
  
    [self post:@"/UserMoney/recharge" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}


//获取用户体现金额
+ (void)moneyWithDrawals:(ByNetModel *)model
                 success:(void(^)(ByNetBaseResult *result))success
                 failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    
    [self post:@"/Usermoney/withdrawals" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}

+ (void)pay:(ByNetModel *)model
    success:(void(^)(ByNetBaseResult *result))success
    failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.money) {
        [params setObject:model.money forKey:@"money"];
    }
    
    if (model.sn) {
        [params setObject:model.sn forKey:@"sn"];
    }
    NSLog(@"money = %@,sn =  %@", model.money,model.sn);
    [self post:@"/UserMoney/pay" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
    
}


//账户明细
+ (void)moneyDetailed:(ByNetModel *)model
              success:(void(^)(ByNetBaseResult *result))success
              failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.type) {
        [params setObject:[NSString stringWithFormat:@"%ld", model.type] forKey:@"type"];
    }else{
        [params setObject:@"1" forKey:@"type"];
    }
    NSLog(@"type = %@", params[@"type"]);
    
    [self post:@"/UserMoney/detailed" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}


//提现
+ (void)withdraw:(ByNetModel *)model
         success:(void(^)(ByNetBaseResult *result))success
         failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.jine) {
        [params setObject:model.jine forKey:@"jine"];
    }
    
    if (model.account) {
        [params setObject:model.account forKey:@"account"];
    }
    
    [self post:@"/UserMoney/toshow" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}


//财务查询接口
+ (void)financeQuerySuccess:(void(^)(ByNetBaseResult *result))success
                    failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [self post:@"/finance/query" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
    
}


//获取用户可用余额
+ (void)moneyAvailable:(ByNetModel *)model
               success:(void(^)(ByNetBaseResult *result))success
               failure:(void(^)(ByNetBaseResult *result))failure{
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [self post:@"/UserMoney/available" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        
        ByModelUser *user = BY_USER;
        user.user_money = result[@"data"];
        [ByCacheUser setUserInfo:user];
        
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}

+ (void)userMoneyFollowSuccess:(void(^)(ByNetBaseResult *result))success
                       failure:(void(^)(ByNetBaseResult *result))failure{
    
    [self get:@"/UserMoney/follow?" params:nil success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}

+ (void)fsPayRecharge:(ByNetModel *)model
              success:(void(^)(ByNetBaseResult *result))success
              failure:(void(^)(ByNetBaseResult *result))failure{
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.money) {
        [params setObject:model.money forKey:@"amount"];
    }
    
    if (model.pay_type) {
        [params setObject:model.pay_type forKey:@"pay_type"];
    }
    [self post:@"/gr_pay/recharge" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
    
}

+ (void)fsPayAlipayQrCode:(ByNetModel *)model
                  success:(void(^)(ByNetBaseResult *result))success
                  failure:(void(^)(ByNetBaseResult *result))failure{
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (model.sn) {
        [params setObject:model.sn forKey:@"sn"];
    }
    
    if (model.pay_type) {
        [params setObject:model.pay_type forKey:@"pay_type"];
    }
    
    if (model.return_url) {
        [params setObject:model.return_url forKey:@"return_url"];
    }
    [self post:@"/gr_pay/lottery_alipay_h5" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
    
}



//提现接口+银行卡
+ (void)userMoneyApply:(ByNetModel *)netModel
               success:(void(^)(ByNetBaseResult *result))success
               failure:(void(^)(ByNetBaseResult *result))failure{
    
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (netModel.account_type) {
        [params setObject:netModel.account_type forKey:@"account_type"];
    }
    
    if (netModel.owner_name) {
        [params setObject:netModel.owner_name forKey:@"owner_name"];
    }
    
    if (netModel.bank_branch_address) {
        [params setObject:netModel.bank_branch_address forKey:@"bank_branch_address"];
    }
    
    if (netModel.account) {
        [params setObject:netModel.account forKey:@"account"];
    }
    
    if (netModel.money) {
        [params setObject:netModel.money forKey:@"money"];
    }
    
    NSLog(@"money = %@", netModel.money);
    
    [self post:@"/UserMoney/apply" params:params success:^(id result) {
        
        ByNetBaseResult *result1 = [[ByNetBaseResult alloc] init];
        result1.code = 0;
        result1.msg = @"获取成功";
        result1.data = result;
        if(success) {
            success(result1);
        }
    } failure:^(NSError *error) {
        
        ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
        result.code = error.code;
        result.msg = error.domain;
        result.data = error.localizedDescription;
        if(failure) {
            failure(result);
        } else {
            
        }
        
    }];
    
}


@end
